import java.util.Scanner;

public class Phonebook {
	Person[] phonebook;

	public Phonebook(Person[] phonebook) {
		this.phonebook = phonebook;
	}

	public void addContactToMass(Person p) {
		int i = 0;
		phonebook = new Person[100];
		phonebook[i] = p;
		i++;
	}
	public void readContact(String name, String surname, int age, String phone){
		Scanner sc = new Scanner(System.in);
		System.out.println("Enter a name: ");
		name = sc.nextLine();
		System.out.println("Enter a surname: ");
		surname = sc.nextLine();
		System.out.println("Enter an age: ");
		age = sc.nextInt();
		System.out.println("Enter a phone number: ");
		phone = sc.nextLine();
		sc.close();
	}
	public void showAll() {
		for (int i = 0; i < phonebook.length; i++) {
			System.out.println(i + ". " + phonebook[i]);
		}
	}

	public void showContact(Person p) {
		for (int i = 0; i < phonebook.length; i++) {
			if (p.equals(phonebook[i])) {
				System.out.println(i + ". " + phonebook[i]);
			}
		}
	}
	public Person searchByName(){
		for(int i=0; i< phonebook.length; i++){
			if(phonebook[i].matchByName(phonebook[i].name)){
				return phonebook[i];
			}
		}
		return null;
	}
	public Person searchBySurname(){
		for(int i=0; i< phonebook.length; i++){
			if(phonebook[i].matchBySurname(phonebook[i].surname)){
			return phonebook[i];
			}
		}
		return null;
	}
	public Person searchByAge(){
		for(int i=0; i< phonebook.length; i++){
			if(phonebook[i].matchByAge(phonebook[i].age)){
			return phonebook[i];
			}
		}
		return null;
	}
	public Person searchByPhone(){
		for(int i=0; i< phonebook.length; i++){
			if(phonebook[i].matchByPhone(phonebook[i].phone)){
			return phonebook[i];
		}
		return null;
	}
		return null;
	
}
	}